home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / tsrfil10 / capture.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-08  |  3.1 KB  |  107 lines

  1. // Written by Scott Hall of the U. of Missouri - Columbia, USA.  
  2. // This program will redirect your print screen button so that 
  3. // it goes to a file.  The file name is at the beginning of the 
  4. // start() function.  It can easily be modified to print screens
  5. // that are larger than 80x25.  
  6.  
  7. #include <stdio.h>
  8. #include <fcntl.h>
  9. #include <io.h>
  10. #include <dos.h>
  11.  
  12. #define VIDMEM 0xB8000000L                      // or 0xb0000000 for mono
  13.  
  14. int busy=0;                                     // mutual exclusion (MUTEX)
  15.  
  16. void interrupt int_5();
  17. void tsr(unsigned size);                        // standard tsr bios call
  18. void write_char(int x, int y, char ch, int attrib);
  19. void write_string(int x, int y, char *str, int attrib);
  20. void main(void);
  21. void start(void);
  22.  
  23. void main(void)
  24. {
  25. struct address  {
  26.     char far *p;
  27.         };
  28.  
  29. struct address far *addr = (struct address far *) 20;
  30.  
  31. addr->p = (char far *) int_5;
  32.  
  33. tsr(500);                               // keeps 500 * 16 bytes resident (8k)
  34. }
  35.  
  36. void tsr(unsigned size)                 // standard tsr bios call
  37. {                                       // you can also use keep()
  38. union REGS r;
  39.  
  40. r.h.ah = 49;                            // function 0x31
  41. r.h.al = 0;
  42. r.x.dx = size;
  43. int86(0x21,&r, &r);                     // last line executed
  44. }                                       // never get to this line
  45.  
  46. void interrupt int_5()                  // print screen button starts here
  47. {
  48. if(!busy)
  49.     {
  50.     busy = !busy;                   // mutex around tsr
  51.     start();
  52.     busy = !busy;
  53.     }
  54. }
  55.  
  56. void write_char(int x, int y, char ch, int attrib)
  57. {                                       // displays 1 character at (x,y)
  58. char far *v;
  59.  
  60. v = (char far *) VIDMEM;
  61. v += y*160 + x*2;
  62. *v++ = ch;
  63. *v = attrib;
  64. }
  65.  
  66. void write_string(int x, int y, char *str, int attrib)
  67. {                                       // writes string str at (x,y)
  68. for( ; *str; str++,x++)
  69.     write_char(x, y, *str, attrib);
  70. }
  71.  
  72. void start(void)
  73. {
  74. int fd,x,y;
  75. char cr=0x0D, lf=0x0A;
  76.  
  77. if((fd =_open("c:\\temp\\log.txt",O_WRONLY))<0) // open the file
  78.     if((fd =_creat("c:\\temp\\log.txt",_A_NORMAL))<0) // try to make new
  79.         write_string(1,1,"OOPS--write error1",0x8F);
  80.  
  81. lseek (fd,0,SEEK_END);                          // jump to end of file
  82.  
  83. for(y=0;y<25;y++)                               // grab lines 0 to 24
  84.     {
  85.     for(x=0;x<80;x++)                       // grab rows 0 through 79
  86.         if(_write(fd,(char far *)(VIDMEM+160*y+2*x),1)==-1)
  87.             write_string(1,2,"OOPS--write error2",0x8F);
  88.  
  89.     if(_write (fd,&cr,1)==-1)               // put a cr and lf at end
  90.         write_string(1,3,"OOPS--write error3",0x8F); // of line
  91.  
  92.     if(_write (fd,&lf,1)==-1)
  93.         write_string(1,4,"OOPS--write error4",0x8F);
  94.     }
  95.  
  96. if(_write (fd,"---<END OF SCREEN>---",21)==-1)          // show end of screen
  97.     write_string(1,5,"OOPS--write error5",0x8F);
  98.  
  99. if(_write (fd,&cr,1)==-1)               // put a cr and lf at end
  100.     write_string(1,6,"OOPS--write error6",0x8F); // of line
  101.  
  102. if(_write (fd,&lf,1)==-1)
  103.     write_string(1,7,"OOPS--write error7",0x8F);
  104.  
  105. _close(fd);                                     // close the file
  106. }
  107.